package com.xkstream.client.presenter;

import com.xkstream.client.api.UserApi;
import com.xkstream.client.api.UserService;
import com.xkstream.client.base.BaseData;
import com.xkstream.client.base.BasePresenterImpl;
import com.xkstream.client.entity.Area;
import com.xkstream.client.entity.User;
import com.xkstream.client.rx.RxHelper;
import com.xkstream.client.rx.RxObserver;

import java.util.List;

/**
 * Created by xiaoyi on 2017-8-28.
 */

public class AreaCodePresenter extends BasePresenterImpl implements AreaCodeContract.Presenter {
    private AreaCodeContract.View view;
    private UserService userService;

    public AreaCodePresenter(AreaCodeContract.View view) {
        this.view = view;
        userService = UserApi.getInstance().service;
    }


    @Override
    public void getAreaList() {
        view.showLoading();
        userService.getAreaList()
                .compose(RxHelper.toUI())
                .subscribe(new RxObserver<BaseData<List<Area>>>(this) {
                    @Override
                    protected void onSuccess(BaseData<List<Area>> listBaseData) {
                        view.hideLoading();
                        view.showAreaList(listBaseData);
                    }

                    @Override
                    protected void onFail(String message) {
                        view.hideLoading();
                    }
                });
    }
}
